package com.amat0urheu.dao;


import com.amat0urheu.pojo.CloudPojo.NetWork;
import com.amat0urheu.pojo.CloudPojo.OpenStack;

import org.apache.ibatis.annotations.*;

import java.util.List;
@Mapper
public interface CloudMapper   {
    @Select("select * from mc_openstack_server")
    List<OpenStack> getAllOpenstack();
    @Select("select * from mc_openstack_server where  openstackIP=#{openstackIP}")
    OpenStack  getOpenstackByopenstackIP(String openstackIP);

    @Select("select openstackIP from mc_openstack_server")
    List<String> getAllOpenstackIP();
    @Select("select * from mc_openstack_server where openstackIP=#{openstackIP}")
    OpenStack findOpenstackByIp(String openstackIP);
    @Select("select count(*) from mc_network where openstackIP=#{openstackIP} ")
    Integer getNetworksNumByOpenstackIP(String openstackIP);
    @Update("update mc_openstack_server set authurl=#{openStack.authUrl},username=#{openStack.username},password=#{openStack.password},projectid=#{openStack.projectid},userDomainName=#{openStack.userDomainName},projectDomainName=#{openStack.projectDomainName},openstackIP=#{openStack.openstackIP} where Id=#{openStack.id}")
    int updateOpenstack(@Param("openStack")OpenStack openStack);
    @Insert("insert into mc_openstack_server (authurl,username,password,projectid,userdomainname,projectDomainName,openstackIP)values(#{openStack.authUrl},#{openStack.username},#{openStack.password}, #{openStack.projectid},#{openStack.userDomainName},#{openStack.projectDomainName},#{openStack.openstackIP})")
    int saveOpenstack(@Param("openStack")OpenStack openStack);
    @Delete(("delete from  mc_openstack_server where  id=#{id}"))
    int removeOpenstackById(Integer id);

    @Select("select count(*) from  mc_openstack_server  ")
    Integer getCountOpenstack();
@Select("SELECT * FROM mc_openstack_server WHERE countVm = (SELECT MIN(countVm) FROM mc_openstack_server) LIMIT 1")
    OpenStack getMinVmNumofOpenstack();
    @Update("update mc_openstack_server set countVm=countVm+1 where openstackIP=#{openstackIP}")
    void updatecountVmOfOpenstack(String openstack);
}
